import Vue from 'vue'

import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		//公共的变量，这里的变量不能随便修改，只能通过触发mutations的方法才能改变
		userInfo: uni.getStorageSync('userInfo'),
		token: uni.getStorageSync('token'),
		platform: ''
	},
	mutations: {
		//相当于同步的操作
		setUserInfo(state, userInfo) {
			state.userInfo = userInfo;
			uni.setStorageSync('userInfo', userInfo)
		},
		setToken(state, token) {
			state.token = token;
			uni.setStorageSync('token', token)
		},
		clearUserInfo(state) {
			uni.removeStorageSync('token')
			uni.removeStorageSync('userInfo')
			state.token = '';
			state.userInfo = {};
		},
		setCurrrentPlatform(state, platform) {
			state.platform = platform
		}
	},
	actions: {
		//相当于异步的操作,不能直接改变state的值，只能通过触发mutations的方法才能改变
	}
})
export default store
